package com.jdbc.framemain;

import com.jdbc.dao.impl.jdbcdaoimpl;
import com.jdbc.dao.jdbcdao;
import com.jdbc.entity.jdbc;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class mainframe extends JFrame {
    private static JFrame jf;
    private static JLabel jl;
    private static JButton bt_add;
    private static JButton bt_delete;
    private static JButton bt_update;
    private static JButton bt_selectbyname;
    private static JButton bt_selectall;
    private static JButton bt_exit;
    private static JTextField jt_id;
    private static JTextField jt_name;
    private static JTextField jt_sexuality;
    private static JTextArea ja;


    public mainframe() {
        jf = new JFrame("数据库管理系统");
        jf.setVisible(true);
        jf.setBounds(10, 10, 640, 600);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jl = new JLabel();
        jt_id = new JTextField("请输入id");
        jt_name = new JTextField("请输入姓名");
        jt_sexuality = new JTextField("请输入性别");
        bt_add = new JButton("增加记录");
        bt_delete = new JButton("删除记录");
        bt_update = new JButton("修改记录");
        bt_selectbyname = new JButton("按照名字查找");
        bt_selectall = new JButton("输出所有记录");
        bt_exit = new JButton("退出");
        ja = new JTextArea();
        jt_sexuality.setBounds(50, 30, 100, 30);
        jt_name.setBounds(180, 30, 100, 30);
        jt_id.setBounds(310, 30, 100, 30);
        ja.setBounds(30, 80, 400, 450);
        bt_exit.setBounds(490, 470, 115, 50);
        bt_selectall.setBounds(490, 390, 115, 50);
        bt_selectbyname.setBounds(490, 310, 115, 50);
        bt_update.setBounds(490, 230, 115, 50);
        bt_delete.setBounds(490, 150, 115, 50);
        bt_add.setBounds(490, 70, 115, 50);
        jl.add(bt_selectbyname);
        jl.add(bt_add);
        jl.add(bt_delete);
        jl.add(bt_update);
        jl.add(bt_selectall);
        jl.add(bt_exit);
        jl.add(ja);
        jl.add(jt_name);
        jl.add(jt_id);
        jl.add(jt_sexuality);
        jf.add(jl);
        bt_exit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    setupframe.con.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }
                System.exit(0);
            }
        });
        bt_add.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

            }
        });
        bt_delete.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //具体代码编写在这里

            }
        });
        bt_update.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //具体代码编写在这里

            }
        });
        bt_selectbyname.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //具体代码编写在这里
            }
        });
        bt_selectall.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jdbcdaoimpl jdbcdaoimpl = new jdbcdao();
                List<String> list1 = new ArrayList<>();
                list1 = jdbcdaoimpl.selectAllPeople();
                String sum;


                }

        });
    }
}